package com.hjc.answer.controller;

import com.hjc.answer.model.QuestionProj;
import com.hjc.answer.service.impl.QuestionServiceImpl;
import com.hjc.answer.tools.GsonTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: HJC
 * Date: 2019/11/15
 * Time: 9:39
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("question")
public class QuestionCtl {

    @Autowired
    private QuestionServiceImpl questionService;

    @RequestMapping( value = "queryLimit" , method = RequestMethod.POST ,produces = "text/json;charset=UTF-8")
    @ResponseBody
    public String queryLimit(String subid ,String count){
        //切割前台得到的json array
        String subids[] = subid.split(",");
        Integer intarr[] = new Integer[subids.length];

        for (int i = 0; i < subids.length ; i++) {
            //正则处理
            subids[i] = subids[i].replaceAll("\"","");
            subids[i] = subids[i].replaceAll("\\[","");
            subids[i] = subids[i].replaceAll("\\]","");
            //to integer
            intarr[i] = Integer.parseInt(subids[i]);
        }
        List<QuestionProj> query = questionService.queryQuestionId(intarr,Integer.parseInt(count));
        GsonTools gsonTools = GsonTools.getGsonTools();
        return gsonTools.tojsons(query);
    }

    @RequestMapping("answer")
    public String answer(){
        System.out.println("enter: answer views");
        return "questionFloor";
    }

    @RequestMapping("refortq")
    public String refortq(){
        return "redirect:/question/refort";
    }
    @RequestMapping("refort")
    public String refort(){
        return "subjectChoose";
    }
}
